<template>
  <view>
    <view class="test">
      <web-view
        :webview-styles="webviewStyles"
        :src="htmlSrc"
        @message="handleMessage"
      ></web-view>
    </view>
  </view>
</template>

<script>
	
export default {
  data() {
    return {
      newsContent: "",
      htmlSrc: "",
      webviewStyles: {
        progress: "#FF3333"
      },
      token: '',
      thumb: "",
      title: "",
	  description:"",
	  shareimage:"",
    }
  },
  onLoad(options) {
	
    const _this = this;
    _this.token = uni.getStorageSync('token');
	
    if (options.link.indexOf('?') > -1) {
      this.htmlSrc = options.link;
    } else {
      this.htmlSrc = options.link + '?id=' + options.id;
      // this.htmlSrc = 'http://www.creb.com.cn/staticdir/www/index.html';
    }
    if (_this.token) {
      this.htmlSrc += '&token=' + _this.token;
    }
	
	// var img = $('#shareimage').src;
    // _this.thumb = img;
	
	// _this.shareimage = options.shareimage;
	// _this.description = options.description;
	_this.thumb = options.thumb;
    _this.title = options.title;
  },
  methods: {
    // 分享到微信聊天页面
    shareWxSession() {
      this.share("weixin", "WXSceneSession")
    },
    // 分享到微信朋友圈
    shareWxTimeline() {
      this.share("weixin", "WXSenceTimeline")
    },
    // 分享到微博
    shareSinaWeibo() {
        uni.share({
            provider: 'sinaweibo',
            type: 1,
            href: this.htmlSrc,
            title: this.title,
            summary: '影响每个热衷思考的人',
            success: function (res) {
                console.log("success:" + JSON.stringify(res));
            },
            fail: function (err) {
                console.log("fail:" + JSON.stringify(err));
            }
        });
    },
    // 分享到qq
    shareQq() {
      this.share("qq")
    },
    share(type, scene) {
      uni.share({
        provider: type,
        scene: scene,
        type: 0,
        href: this.htmlSrc,
        title: this.title,
        summary: "影响每个热衷思考的人",
        // summary: this.title,
        // imageUrl: this.thumb ? this.thumb : "http://cmszfb.oss-cn-beijing.aliyuncs.com/u/cms/www/202005/11234934cm3y.png",
        // imageUrl:img,
        // imageUrl: this.thumb ? this.thumb : 'http://cmszfb.oss-cn-beijing.aliyuncs.com/u/cms/www/202105/17152543t7xk.png',
        imageUrl: 'http://cmszfb.oss-cn-beijing.aliyuncs.com/u/cms/www/202108/25160614ry41.jpg',
		success: function (res) {
          console.log("success:" + JSON.stringify(res));
        },
        fail: function (err) {
          console.log("fail:" + JSON.stringify(err));
        }
      });
    },
    handleMessage(evt) {
      let action = evt.detail.data[0].action;
      if (action == 'share-tx-weChat') {
        this.shareWxSession();
      } else if (action == 'share-tx-friends') {
        this.shareWxTimeline();
      } else if (action == 'share-xl-weiBo') {
        this.shareSinaWeibo();
      } else if(action == 'share-xl-qq') {
        this.shareQq();
      }
    }
  }
}
</script>

<style>
</style>
